var crypto=require('crypto');
var mongoose=require('mongoose');
var moment=require('moment');
var UserSchema = new mongoose.Schema({
    name:{
        type:String,
        required:true
    },
    password:{
        type:String,
        required:true,
        set:function(pass){
            if(!pass || 'string'!==typeof pass)pass='';
            return crypto.createHash('md5').update(pass).digest('hex');
        }
    },
    regDate:{
        type:Date,
        //default:new Date(),
        get: function (date) {
            return moment(date).format('YYYY-MM-DD HH:mm:ss');
        }
    }
});

module.exports=mongoose.model('User',UserSchema);